﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Kooboo.IoC;
using Kooboo.Commerce;


namespace Kooboo.Web.Areas.Commerce.Binders
{
    public class SubTaxBinder:EntityBinder
    {
        protected override string[] SkipProperties
        {
            get
            {
                return new string[] { "Country" };
            }
        }

        protected override object CreateModel(System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ModelBindingContext bindingContext, Type modelType)
        {
            var model = ObjectContainer.CreateInstance<ISubTax>();

            var form = controllerContext.HttpContext.Request.Form;

            var countrycode = form["Country.CountryCode"];

            if(string.IsNullOrWhiteSpace(countrycode) == false)
            {
                var country = ObjectContainer.CreateInstance<ICountry>();

                country.CountryCode = countrycode;

                model.Country = country;
            }

            return model;
        }
    }
}